package com.example.dataextraction.controller;

import com.example.dataextraction.model.DataSource;
import com.example.dataextraction.service.DataSourceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author Zenan Chen
 * @date 2023/3/30 17:25
 */
@Api(tags = "数据源控制器")
@RestController
@RequestMapping("/dataSource")
public class DataSourceController {

    private static final Logger log = LoggerFactory.getLogger(DataSourceController.class);
    @Autowired
    private DataSourceService dataSourceService;

    @ApiOperation(value = "新增数据源")
    @PostMapping("/save")
    public Object createDataBase(@Validated @RequestBody DataSource dataSource) {
        try {
            dataSourceService.insert(dataSource);
            return "新增数据源成功！";
        } catch (Exception e) {
            log.error("------------->/dataSource/save 接口异常: ", e);
            return "新增数据源失败：" + e.getMessage();
        }
    }

}
